package com.ruoyi.project.system.recommendtitle.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.recommendtitle.domain.RecommendTitle;
import com.ruoyi.project.system.recommendtitle.service.IRecommendTitleService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 推荐标题Controller
 * 
 * @author ruoyi
 * @date 2021-05-24
 */
@Controller
@RequestMapping("/system/recommendtitle")
public class RecommendTitleController extends BaseController
{
    private String prefix = "system/recommendtitle";

    @Autowired
    private IRecommendTitleService recommendTitleService;

    @RequiresPermissions("system:recommendtitle:view")
    @GetMapping()
    public String recommendtitle()
    {
        return prefix + "/recommendtitle";
    }

    /**
     * 查询推荐标题列表
     */
    @RequiresPermissions("system:recommendtitle:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecommendTitle recommendTitle)
    {
        startPage();
        List<RecommendTitle> list = recommendTitleService.selectRecommendTitleList(recommendTitle);
        return getDataTable(list);
    }

    /**
     * 导出推荐标题列表
     */
    @RequiresPermissions("system:recommendtitle:export")
    @Log(title = "推荐标题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RecommendTitle recommendTitle)
    {
        List<RecommendTitle> list = recommendTitleService.selectRecommendTitleList(recommendTitle);
        ExcelUtil<RecommendTitle> util = new ExcelUtil<RecommendTitle>(RecommendTitle.class);
        return util.exportExcel(list, "推荐标题数据");
    }

    /**
     * 新增推荐标题
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存推荐标题
     */
    @RequiresPermissions("system:recommendtitle:add")
    @Log(title = "推荐标题", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RecommendTitle recommendTitle)
    {
        return toAjax(recommendTitleService.insertRecommendTitle(recommendTitle));
    }

    /**
     * 修改推荐标题
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RecommendTitle recommendTitle = recommendTitleService.selectRecommendTitleById(id);
        mmap.put("recommendTitle", recommendTitle);
        return prefix + "/edit";
    }

    /**
     * 修改保存推荐标题
     */
    @RequiresPermissions("system:recommendtitle:edit")
    @Log(title = "推荐标题", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RecommendTitle recommendTitle)
    {
        return toAjax(recommendTitleService.updateRecommendTitle(recommendTitle));
    }

    /**
     * 删除推荐标题
     */
    @RequiresPermissions("system:recommendtitle:remove")
    @Log(title = "推荐标题", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(recommendTitleService.deleteRecommendTitleByIds(ids));
    }
}
